package com.xinpu.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xinpu.entity.TSalesFriendsBack;
import com.xinpu.service.ITSalesFriendsBackService;
import com.xinpu.vo.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * SalesFriendsBackController
 *
 * @author ayuan
 * @date 2021/6/3
 */
@RestController
@RequestMapping("/salesFriendsBack")
public class SalesFriendsBackController {

    @Autowired
    private ITSalesFriendsBackService itSalesFriendsBackService;


    /**
     * 朋友圈默认背景
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseMessage list() {
        return ResponseMessage.ok(itSalesFriendsBackService.list(Wrappers.<TSalesFriendsBack>lambdaQuery().eq(TSalesFriendsBack::getSid, 0)));
    }

    /**
     * 创建或编辑朋友圈默认背景
     *
     * @param map
     * @return
     */
    @PostMapping("/createOrEdit")
    public ResponseMessage createOrEdit(@RequestBody Map<String, String> map) {
        TSalesFriendsBack tSalesFriendsBack = new TSalesFriendsBack();
        String id = map.get("id");
        if (StringUtils.isNotBlank(id)) {
            tSalesFriendsBack.setId(Integer.parseInt(id));
        }
        tSalesFriendsBack.setPortrait(map.get("portrait"));
        tSalesFriendsBack.setImg(map.get("img"));
        itSalesFriendsBackService.saveOrUpdate(tSalesFriendsBack);
        return ResponseMessage.ok();
    }


}
